from fastapi import FastAPI
from pydantic import BaseModel
from fastapi.staticfiles import StaticFiles
from fastapi_offline import FastAPIOffline
import uvicorn

app = FastAPIOffline()
app.mount('/static', StaticFiles(directory='static'),
          name='static')

class User(BaseModel):
    id: int
    name: str
    age: int
    gender: str


mock_datas = [
    {"id": 1001, "name": "王", "age": 12, "gender": "男"},
    {"id": 1002, "name": "刘", "age": 20, "gender": "男"},
    {"id": 1003, "name": "陈", "age": 18, "gender": "女"},
]


@app.get("/user/{user_id}", response_model=User)
async def get_user(user_id: int):
    for user in mock_datas:
        if user_id == user["id"]:
            return user


if __name__ == '__main__':
    uvicorn.run(app, port=8888)
